//==========================================================================
// Copyright (c) 2000-2006,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef ___DISPLAY_DEF_H__
#define ___DISPLAY_DEF_H__

#include "display.h"
#include <err.h>


//#define DEBUG_DISPLAY
#ifdef DEBUG_DISPLAY

#define DBGOUT(m, x)  if ((m)) printk x
#define DBGOUT_FUNC(m, x) if ((m)) x
#define DBG_ERR     1
#define DBG_LOG     1
#define DBG_DUMP    1
#define DBG_POWER   1

#else

#define DBGOUT(m, x)
#define DBGOUT_FUNC(m, x)

#endif


#define LCD_WIDTH		240
#define LCD_HEIGHT		320
#define LCD_BPP_DIS		16	// bit per pixel

#define BASEPLANE_COLORFORMAT   COLOR_RGB565  // default
#define BASEPLANE_PIXELBYTES    2
#define BASEPLANE_PIXELBITS     16
#define DRVBUF_SPEED_FAST   0x1
#define DEVBUF_REALLOC_COPY 0x2
#define OVERLAY1_PIXELBYTES 4
#define PAGE_SHIFT          12
#define __PAGESIZE 0x1000
#define ROUNDUP_PAGE(n)     (((n) + (__PAGESIZE) - 1) & ~((__PAGESIZE) - 1))

#define DESC_SIZE            (0x20)
#define BASEPLANE_FB_SIZE    \
    ROUNDUP_PAGE((LCD_WIDTH * LCD_HEIGHT * BASEPLANE_PIXELBYTES))

#define BASEPLANE_FB_PAGES (BASEPLANE_FB_SIZE >> PAGE_SHIFT)

typedef struct {

    // Physical address of frame buffer
    unsigned int paBasePlane ;
    unsigned int paOverlay1  ;
    unsigned int paOverlay2Y ;
    unsigned int paOverlay2Cb;
    unsigned int paOverlay2Cr;
    unsigned int paPalette;

    // Virtual address of frame buffer
    unsigned int vaBasePlane ;
    unsigned int vaOverlay1  ;
    unsigned int vaOverlay2Y ;
    unsigned int vaOverlay2Cb;
    unsigned int vaOverlay2Cr;
    unsigned int vaPalette;

    // Physical address of DMA descriptors
    unsigned int paChan0Desc ; // Baseplane descriptor
    unsigned int paChan1Desc ; // Overlay1 channel descriptor
    unsigned int paChan2Desc ; // Overlay2 Y channel descriptor
    unsigned int paChan3Desc ; // Overlay2 Cb channel descriptor
    unsigned int paChan4Desc ; // Overlay2 Cr channel descriptor
    unsigned int paChan1AltDesc; // Overlay1 alterable channel descriptor
    unsigned int paPaletteDesc; // Palette descriptor

    // Virtual address of DMA descriptors
    unsigned int vaChan0Desc ; // Baseplane descriptor
    unsigned int vaChan1Desc ; // Overlay1 channel descriptor
    unsigned int vaChan2Desc ; // Overlay2 Y channel descriptor
    unsigned int vaChan3Desc ; // Overlay2 Cb channel descriptor
    unsigned int vaChan4Desc ; // Overlay2 Cr channel descriptor
    unsigned int vaChan1AltDesc; // Overlay1 alterable channel descriptor
    unsigned int vaPaletteDesc; // Palette descriptor

    // DMA transfer size
    unsigned int uChan0Size;
    unsigned int uChan1Size;
    unsigned int uChan2Size;
    unsigned int uChan3Size;
    unsigned int uChan4Size;

    // Baseplane
    ColorFormat basePlaneFormat;

    // Overlay
    OverlayFormat overlay[3]; // 0 reserved
        // 1 ~ 2 for Overlay1 & Overlay2


} DisplayContext;

//
// Functions
//

ECODE Display_Create(DisplayContext *pCxt);
ECODE Display_Init(DisplayContext *pCxt);
ECODE Display_ChangeBasePlaneFormat(DisplayContext *pCxt, ColorFormat format);

void LcdCtrl_Init(DisplayContext *pCxt);
void LcdCtrl_Enable(DisplayContext *pCxt);
void LcdCtrl_Disable(DisplayContext *pCxt);
void LcdCtrl_Suspend(DisplayContext *pCxt, int type);
void LcdCtrl_Resume(DisplayContext *pCxt);

void Lcm_DisplayOn(DisplayContext *pCxt);
void Lcm_DisplayOff(DisplayContext *pCxt);

void BackLight_Open();
void ostdelay(int uSec);

ulong_t GetGedrValue(long RegIdx);
void Gpio_SetDir(int gpio_num, int direction);
void Gpio_SetAFR(int gpio_num, int function);
void Gpio_SetOutLow(int gpio_num);
void Gpio_SetOutHigh(int gpio_num);
void pxa_set_cken(int clock, int enable);
void pxa3xx_enable_lcd_pins(void);



#endif // ___DISPLAY_DEF_H__
